package com.example.demopublish.controller;


import com.example.demopublish.dto.ResponseData;
import com.example.demopublish.dto.UserDto;
import com.example.demopublish.service.JwUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiangwei
 * @since 2025-01-07
 */
@RestController
@RequestMapping("/jwUser")
public class JwUserController {

    @Value(value = "${jw.note}")
    private String note;

    @Autowired
    private JwUserService jwUserService;

    @PostMapping(value = "/create")
    public ResponseData createUser(@RequestBody UserDto userDto) {
        try {
            jwUserService.saveOne(userDto);
            return ResponseData.ok();
        } catch (Exception ex) {
            return ResponseData.error("插入失败");
        }
    }

    @PostMapping(value = "/selectPageInfo")
    public ResponseData selectPageInfo(@RequestBody UserDto userDto) {
        try {
            return ResponseData.ok(jwUserService.selectPageInfo(userDto));
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseData.error("查询失败");
        }
    }

    @GetMapping(value = "/test")
    public ResponseData test(){
        return ResponseData.ok(note);
    }


}

